import java.util.*;
public class Test {

    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(),b = in.nextInt();

        int c = 0;
        for (int i = a; i <= b; i++) {
            c += check(i);
        }

        System.out.println(c);
    }

    private static boolean isPrim(int num){
        if(num < 2) return false;

        for(int i = 2;i <= Math.sqrt(num);i++){
            if(num % i == 0) return false;
        }
        return true;
    }

    public static int check(int num){
       int[] cnt = new int[10];

       int n = 0;
       while(num != 0){
           cnt[n++] = num % 10;
           num /= 10;
       }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(i != j && cnt[i] != 0){
                    if(isPrim(cnt[i] * 10 + cnt[j])){
                        return 1;
                    }
                }
            }
        }
        return 0;
    }
}
